import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/components/Login')
  },
  {
    path: '/home',
    name: 'home',
    redirect:'/users',
    component: () => import('@/components/Home'),
    children: [
      { path: '/users', component: () => import('@/components/users/users') },
      { path: '/roles', component: () => import('@/components/users/roles') }
    ]
  },
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  console.log(to, 6666);
  /* 
  p

  */
  var token = window.sessionStorage.getItem('token')

  /* 这里拦截是不是进入login */
  if (to.path == '/login') {
    return next()
  }
  /* 是不是已经登录 */
  if (!token) {
    return next('/login')
  }

  next()

})

export default router
